package com.coder.oj.common.core;

import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.List;

/**
 * 分页查询实体
 * @author Bosen 2022/11/23 14:45
 **/
@Data
public class JsonPage<T> implements Serializable {

    /**
     * 当前页数
     */
    private Integer page;

    /**
     * 每页显示条数
     */
    private Integer pageSize;

    /**
     * 总条数
     */
    private Integer total;

    /**
     * 总页数
     **/
    private Integer pageCount;

    /**
     * 数据列表
     */
    private List<T> list;

    public JsonPage(List<T> data) {
        this.page = 1;
        this.pageSize = data.size();
        this.total = data.size();
        this.list = data;
        this.pageCount = 1;
    }

    public JsonPage(Long pageNum, Long pageSize, Long total, List<T> data) {
        this.page = pageNum.intValue();
        this.pageSize = pageSize.intValue();
        this.total = total.intValue();
        this.list = data;
        this.pageCount = (int) Math.ceil((double) total / pageSize);
    }

    public JsonPage(JsonPage jsonPage, List<T> list) {
        this.page = jsonPage.getPage();
        this.pageSize = jsonPage.getPageSize();
        this.total = jsonPage.getTotal();
        this.list = list;
        this.pageCount = (int) Math.ceil((double) total / pageSize);
    }
}
